
# 保存当前工作目录
$originalLocation = Get-Location

# 设置工作目录为脚本所在目录
Set-Location $PSScriptRoot

# root
$RootPath = Join-Path $PSScriptRoot ".."

$setupName = $args[0]
$version = $args[1]
# $nsiscompiler = "S:\App\1entertainment\NSIS\main\NSIS\makensis.exe"
$nsiscompiler = $args[2]

$productPath = Join-Path $RootPath "release\windows"
$outFilePath = Join-Path $RootPath "release"
$nsisscript = Join-Path $PSScriptRoot "temp2.nsi"

try {
    & $nsiscompiler /DPRODUCT_NAME="$setupName" /DPRODUCT_VERSION="$version" /DPRODUCT_PATH="$productPath\*.*" /DOutFilePath="$outFilePath" $nsisscript
}
catch {
    $errorMessage = $_.Exception.Message
    $errorStackTrace = $_.Exception.StackTrace
    $errorDetails = "Action: $action`nError: $errorMessage`nStack Trace: $errorStackTrace"
    Write-Output "$errorDetails"
    Write-Output "build Nsis failed!!!!"
    exit 1
}
finally {
    # 恢复原始工作目录
    Set-Location $originalLocation
}

